import Vue from 'vue'
import Router from 'vue-router'
import Login from './views/Login.vue'
import Welcome from './views/welcome.vue'
Vue.use(Router)

var router = new Router({
  routes: [
    { path: '/login', component: Login },
    { path: '/home',
      name: 'home',
      component: () => import('@/views/home'),
      redirect: '/welcome',
      children: [{ path: '/welcome', name: 'welcome', component: Welcome }]

    }
  ]
})
// 路由守卫设置
router.beforeEach((to, from, next) => {
  var token = window.sessionStorage.getItem('token')
  if (!token && to.path !== '/login') {
    return next('/login')
  }
  next()
})

export default router
